//
//  BrushAddSubView.m
//  BrushFace
//
//  Created by timer_q on 15/12/11.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "BrushStaticClass.h"
#import "NavHelper.h"
#import "MeStatus.h"
#import "IWillHelper.h"
#import "BorrowScenceModel.h"

#define TagButton (201512)
@implementation BrushStaticClass



+ (void)addJieKuanReasonButtonWith:(UIScrollView *)superView fromMutableArray:(NSMutableArray *)buttonImageArray{
    if (buttonImageArray.count==0||buttonImageArray==nil) {
        return;
    }
    for (UIView *view in superView.subviews) {
        [view removeFromSuperview];
    }
    float cnt = buttonImageArray.count%6;
    if (cnt == 0) {
        cnt = buttonImageArray.count/6;
    }else{
        cnt = buttonImageArray.count/6+1;
    }
    
    superView.contentSize = CGSizeMake(superView.frame.size.width*cnt, 0);
    CGFloat width = superView.frame.size.width/3.0;
    CGFloat height = superView.frame.size.height/2.0;
    for (int i=0; i<buttonImageArray.count; i++) {
        int y = i/3;
        int x = i%3+y/2*3;
        y = y%2;
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x*width, y*height, width, height)];
        [superView addSubview:view];
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, height)];
        [button setImage:[UIImage imageNamed:[buttonImageArray objectAtIndex:i]] forState:UIControlStateNormal];
        button.tag = i+TagButton;
        [button addTarget:self action:@selector(gotoIWillBorrowVCButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
    }
}
#pragma mark - action
+ (void)gotoIWillBorrowVCButtonClick:(UIButton *)sender{
    if ([BrushStaticClass isNeedLogin:YES]) {
        return;
    }
    [IWillHelper sharedInstance].reasonID = sender.tag - TagButton;
    
    BorrowScenceModel *model = [BorrowScenceModel SceneModel];
    [model user_isFace:^(BOOL isFace) {
        if (isFace) {
           [NavHelper gotoIWillBorrowVC];
        }else{
            [NavHelper gotoBrushVC];
        }
    }];
}

+ (BOOL)isNeedLogin:(BOOL)login{
    USER_ACCOUNT_STATUS status = [[MeStatus sharedInstance] userAccountStatus];
    if(status == USER_ACCOUNT_STATUS_VERIFY){
        return NO;
    }else{
        if (login) {
           [NavHelper gotoLoginVC];
        }
        return YES;
    }
}
@end
